package gdconf

import (
	"server_cluster/common/logger"
)

const (
	WishItemIdListMax = 30
)

// 抽卡配置表

type GachaConfig struct {
	Id                  int32    `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 卡池排期id
	GachaType           int32    `csv:"Type,omitempty"`                            // 卡池类型
	BeginTime           *Time    `csv:"Startdate,omitempty"`                       // 开启时间
	EndTime             *Time    `csv:"Enddate,omitempty"`                         // 结束时间
	GachaTimesLimit     int32    `csv:"Trieslimit,omitempty"`                      // 抽卡次数限制
	CostItem            int32    `csv:"Costitem,omitempty"`                        // 单抽消耗道具
	TenCostItemCount    int32    `csv:"Discount,omitempty"`                        // 十连消耗道具数量
	TenCostItemCountNum int32    `csv:"Discountnum,omitempty"`                     // 十连消耗道具数量折扣次数
	ProbId              int32    `csv:"Group,omitempty"`                           // 概率规则id
	DiamondsNum         int32    `csv:"DiamondsNum,omitempty"`                     // 单抽消耗钻石
	GachaConvItem       *Item    `csv:"Getitem,omitempty"`                         // 抽卡转化道具
	WishItemNum         int32    `csv:"Wishnum,omitempty"`                         // 许愿道具数量
	WishItemIdList      IntArray `csv:"Wishitem,omitempty"`                        // 许愿道具id列表

	Front      int32 `csv:"Front,omitempty"`      // 固定抽数
	FrontGroup int32 `csv:"FrontGroup,omitempty"` // 固定抽detail组

	OrdinaryGroup  int32 `csv:"OrdinaryGroup,omitempty"`  // 基本抽卡池
	RequiredSRNum  int32 `csv:"RequiredSRNum,omitempty"`  // SR基本保底次数
	RequiredSRId   int32 `csv:"RequiredSRId,omitempty"`   // SR基本保底池
	RequiredSSRNum int32 `csv:"RequiredSSRNum,omitempty"` // SSR基本保底次数
	RequiredSSRId  int32 `csv:"RequiredSSRId,omitempty"`  // SSR基本保底池

	RequiredUPNum int32 `csv:"RequiredUPNum,omitempty"` // UP池究极保底次数
	RequiredUpId  int32 `csv:"RequiredUpId,omitempty"`  // UP池究极保底道具

	ResetType int32 `csv:"ResetType,omitempty"` // 保底重置规则
}

func (c *GachaConfig) TableName() string {
	return "config_gacha"
}

func (g *GameDataConfig) saveGacha() {
	saveTableToDb[GachaConfig](g.Db, readTable[GachaConfig](g.CsvPathPrefix+"CardGroup.csv"))
}

func (g *GameDataConfig) loadGachaConfig() {
	g.GameDataMaps.GachaMap = make(map[int32]*GachaConfig)
	for _, gacha := range loadTableFromDb[GachaConfig](g.Db) {
		g.GameDataMaps.GachaMap[gacha.Id] = gacha
	}
	logger.Info("GachaConfig Count: %v", len(g.GameDataMaps.GachaMap))
}

func GetConfigGachaMap() map[int32]*GachaConfig { return CONF.GameDataMaps.GachaMap }

func GetConfigGacha(id int32) *GachaConfig {
	data, ok := CONF.GameDataMaps.GachaMap[id]
	if !ok {
		return nil
	}
	return data
}
